<?php

namespace App\Admin\Renderable;

use App\Models\Course;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class CourseTable extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new Course(),function (Grid $grid){
            $grid->model()->with(['user:id,avatar,nickname','category:id,name'])->where('audit_status',1);
            $grid->column('id');
            $grid->column('user.avatar','用户头像')->image('',80,80);
            $grid->column('user.nickname','用户昵称');
            $grid->column('category.name','课程分类');
            $grid->column('name');
            $grid->column('sale_type','销售方式')
                ->using([ 1 => '现金',2 => '积分',3 => '免费'])
                ->label([ 1 => 'danger',2 => 'waring', 3 => 'success']);
            $grid->column('price','价格');
            $grid->column('points','积分');
            $grid->column('status','状态')
                ->using([0 => '隐藏',1 => '显示'])
                ->label([0 => 'danger',1 => 'success']);
            $grid->column('created_at');
            $grid->paginate(10);
            $grid->disableActions();
            $grid->showRowSelector();

            $grid->filter(function (Grid\Filter $filter){
                $filter->like('school_name','学校名称');
            });
        });
    }
}
